package com.ruoyi.miniapp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.miniapp.api.domain.MiniappLogininfor;
import com.ruoyi.miniapp.service.IMiniappLogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统访问记录Controller
 *
 * @author ruoyi
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/logininfor")
public class MiniappLogininforController extends BaseController
{
    @Autowired
    private IMiniappLogininforService miniappLogininforService;

    /**
     * 查询系统访问记录列表
     */
    @RequiresPermissions("miniapp:logininfor:list")
    @GetMapping("/list")
    public TableDataInfo list(MiniappLogininfor miniappLogininfor)
    {
        startPage();
        List<MiniappLogininfor> list = miniappLogininforService.selectMiniappLogininforList(miniappLogininfor);
        return getDataTable(list);
    }

    /**
     * 导出系统访问记录列表
     */
    @RequiresPermissions("miniapp:logininfor:export")
    @Log(title = "系统访问记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniappLogininfor miniappLogininfor)
    {
        List<MiniappLogininfor> list = miniappLogininforService.selectMiniappLogininforList(miniappLogininfor);
        ExcelUtil<MiniappLogininfor> util = new ExcelUtil<MiniappLogininfor>(MiniappLogininfor.class);
        util.exportExcel(response, list, "系统访问记录数据");
    }


    /**
     * 新增系统访问记录
     */
    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody MiniappLogininfor miniappLogininfor)
    {
        return toAjax(miniappLogininforService.insertMiniappLogininfor(miniappLogininfor));
    }



    /**
     * 删除系统访问记录
     */
    @RequiresPermissions("miniapp:logininfor:remove")
    @Log(title = "系统访问记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(miniappLogininforService.deleteMiniappLogininforByInfoIds(infoIds));
    }
}
